<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<link rel="stylesheet" type="text/css" href="js/layui/css/layui.css"/>
	<script src="js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
	<script src="js/layer/layer.js" type="text/javascript" charset="utf-8"></script>
	<script src="js/layui/layui.js" type="text/javascript" charset="utf-8"></script>
	<script src="js/Global.js"></script>
	<body>
		<div id="add-Stuent" style=";" >
		       <form class="layui-form" id="add-form" action="">
				     
				   
				 
				   
			     <div class="layui-form-item">
			 <label class="layui-form-label" style="width: 100px">老师名称</label>
			 <div class="layui-input-block">
			  <input type="text" name="type" id="option1" disabled="disabled" value="sdfsda" required style="width: 240px" lay-verify="required" placeholder="选项1" autocomplete="off" class="layui-input">
			 </div>
			</div>
				   
				      
				   
				   
				     <div class="layui-form-item">
				    <label class="layui-form-label">课程</label>
				   <div class="layui-input-block" style="width: 240px"">
				     <select name="city2" lay-verify="required" id="teach2">
				       <option value="请选择"></option>
				      
				      
				     </select>
				   </div>
				   </div>
				   
				   
				   
				   
		       
				 
				   <div class="layui-form-item">
				  <label class="layui-form-label">班级名称</label>
				 <div class="layui-input-block" style="width: 240px"">
				   <select name="city3" lay-verify="required" id="teach3">
				     <option value="请选择"></option>
				    
				    
				   </select>
				 </div>
				 </div>
				 
				 
				
		
		         </div>
		         <div class="layui-form-item">
		          <div class="layui-input-block">
		          <input type="button" value="保存" id="add1" class="layui-btn">
		        
		          </div>
		         </div> 
		       </form>  
		    </div>
	
	</body>
	
<script>//Demo
layui.use('form', function(){
  var form = layui.form;
  
  //监听提交
  form.on('submit(formDemo)', function(data){
    layer.msg(JSON.stringify(data.field));
    return true;
  });
});
</script>
<script type="text/javascript">
	$(function(){
		var newscript = document.createElement('script');
		newscript.setAttribute('type','text/javascript');
		newscript.setAttribute('src','js/Global.js');
		var head = document.getElementsByTagName('head')[0];
		head.appendChild(newscript);
		
		
		 	 var studentid=window.globalConfig.id;
			 	 var teachername=window.globalConfig.id2;
				 
			
			var   optionstring=""  
			var   optionstring2=""  
				var   optionstring3=""  
				
			/* 	alert(studentid+" "+ decodeURI(studentid2)) */
				$("#option1").val(decodeURI(teachername))
          $.ajax({
			   type:"get",
			    url:"http://127.0.0.1:8080//courseTeacher/lists",
			    
			   contentType:"application/x-www-form-urlencoded;charset=utf-8",
			   
			  
			   success:function(msg){
				   console.log(msg.data.teachers)
			     for(var key=0 in msg.data.teachers ){
					      
						  optionstring += "<option value=\"" +msg.data.teachers[key].teacherid + "\">" +msg.data.teachers[key].teachername  + "</option>"; 
                            $("#teach1").html("<option value='请选择'  >请选择...</option>"+ optionstring); 
						
				 } 
				
				 for(var key=0 in msg.data.courses ){
				 					      
				 		 optionstring2 += "<option value=\"" +msg.data.courses[key].courseid + "\">" +msg.data.courses[key].coursename  + "</option>"; 
				         $("#teach2").html("<option value='请选择'  >请选择...</option>"+ optionstring2); 
				 						
				 } 
				 
				 	 for(var key=0 in msg.data.clazzes ){
				 					      
				 			 optionstring3 += "<option value=\""  +msg.data.clazzes[key].clazzid + "\">" +msg.data.clazzes[key].classname  + "</option>"; 
				            $("#teach3").html("<option value='请选择'  >请选择...</option>"+ optionstring3); 
				 						
				 } 
				 
				 }
		  }) 
		 
		 
		     
		  $("#add1").click(function(){
			  
		    var teacherid=window.globalConfig.ids3;
			alert(teacherid)
			var teach2= $("#teach2").val();
			var teach3= $("#teach3").val();
			 /* alert(teach1+" "+teacherid+" "+teach3) */
        var data={
					 "tccid":studentid,
					"teacherid":teacherid,
					 "courseid":teach2,
					 "clazzid":teach3
				}
	
			$.ajax({
				   type:"get",
				    
				  contentType:"application/x-www-form-urlencoded;charset=utf-8",
				   url:"http://127.0.0.1:8080//courseTeacher//update",
				   data:{
						  "tccid":studentid,
						 "teacherid":teacherid,
						  "courseid":teach2,
						  "clazzid":teach3
					 },
				   success:function(msg){
					   alert(msg.data)
				   },
				   error:function(){
					   alert("失败")
				   }
			})
			 
		
		  })
		
	})
	
</script>

</html>
